package com.example.permissionservice.pojo;

import com.example.permissionservice.pojo.Role;
import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.List;

public class UserWithRole {
    private Integer id;

    @NotBlank(message = "用户名不能为空!")
    @Pattern(regexp = "^([A-Za-z0-9_-]){5,20}$",
            message = "用户名必须为5-20位的英文字符或数字!")
    private String username;

    @NotBlank(message = "昵称不能为空!")
    @Pattern(regexp = "^([^\"]){3,10}$",
            message = "昵称必须为3-10的任意字符!")
    private String nickname;


    @NotBlank(message = "密码不能为空!")
    @Pattern(regexp = "^[A-Za-z0-9]{5,20}$",
            message = "密码必须为5-20位的英文字符或数字!")
    private String password;

    /**
     * 在注册用户时，password2为二次密码<br>
     * 在修改密码时，password2为新密码
     */
    @NotBlank(message = "二次密码不能为空!")
    @Pattern(regexp = "^[A-Za-z0-9]{5,20}$",
            message = "密码必须为5-20位的英文字符或数字!")
    private String password2;

    @JsonIgnore
    private String encrypt_password;

    @NotBlank(message = "邮箱不能为空!")
    @Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$",
            message = "邮箱格式错误!")
    private String email;

    private List<Role> roleList;

    private List<Integer> roleIdList;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname == null ? null : nickname.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password == null ? null : password.trim();
    }

    public String getPassword2() {
        return password2;
    }

    public void setPassword2(String password2) {
        this.password2 = password2;
    }

    public String getEncrypt_password() {
        return encrypt_password;
    }

    public void setEncrypt_password(String encrypt_password) {
        this.encrypt_password = encrypt_password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }

    public List<Role> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    public List<Integer> getRoleIdList() {
        return roleIdList;
    }

    public void setRoleIdList(List<Integer> roleIdList) {
        this.roleIdList = roleIdList;
    }

    @Override
    public String toString() {
        return "UserWithRole{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", nickname='" + nickname + '\'' +
                ", password='" + password + '\'' +
                ", password2='" + password2 + '\'' +
                ", encrypt_password='" + encrypt_password + '\'' +
                ", email='" + email + '\'' +
                ", roleList=" + roleList +
                ", roleIdList=" + roleIdList +
                '}';
    }
}